//
//  GetScheduleListTask.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-6-20.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "GetScheduleListTask.h"
#import "WebServiceHelper.h"
#import "StringUtil.h"
#import "ScheduleInfo.h"
#import "GDataXMLNode.h"

@implementation GetScheduleListTask

-(void)execute
{
    NSString *ValidateData = [self.params objectForKey:@"ValidateData"];
    NSString *url = [self.params objectForKey:@"url"];
    NSString *wsNamespace = [self.params objectForKey:@"namespace"];
    NSString *userguid = [self.params objectForKey:@"userguid"];
    NSString *FromDateTime = [self.params objectForKey:@"FromDateTime"];
    NSString *ToDateTime = [self.params objectForKey:@"ToDateTime"];
    NSString *KeyWord = [self.params objectForKey:@"KeyWord"];
    
    WebServiceHelper *webserviceHelper = [[WebServiceHelper alloc]initWebServiceWithUrl:url wsNamespace:wsNamespace method:@"Schedule_GetList"];
    
    NSString *ParasXml = @"<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><KeyWord>%@</KeyWord><FromDateTime>%@</FromDateTime><ToDateTime>%@</ToDateTime></paras>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,KeyWord,FromDateTime,ToDateTime];
    ParasXml = [StringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    [self sendDataRefreshUI:bs];
}

+(NSMutableArray *)getList:(NSString *)_xml
{
    _xml = [StringUtil getXMLFormatedAttributeIncludeTag:_xml :@"ScheduleList"];
    
    GDataXMLDocument *doc = [[[GDataXMLDocument alloc] initWithXMLString:_xml  options:0 error:nil]autorelease];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"ScheduleInfo"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        ScheduleInfo *m = [[ScheduleInfo alloc]init];
        GDataXMLElement *ActivityID = [[arr elementsForName:@"ActivityID"] objectAtIndex:0];
        m.ActivityID = [ActivityID stringValue];
        
        GDataXMLElement *Subject = [[arr elementsForName:@"Subject"] objectAtIndex:0];
        m.Subject = [Subject stringValue];
        
        GDataXMLElement *Location = [[arr elementsForName:@"Location"] objectAtIndex:0];
        m.Location = [Location stringValue];
        
        GDataXMLElement *IsRecurrence = [[arr elementsForName:@"IsRecurrence"] objectAtIndex:0];
        m.IsRecurrence = [IsRecurrence stringValue];
        
        GDataXMLElement *FromDateTime = [[arr elementsForName:@"FromDateTime"] objectAtIndex:0];
        m.FromDateTime = [FromDateTime stringValue];
        
        GDataXMLElement *ToDateTime = [[arr elementsForName:@"ToDateTime"] objectAtIndex:0];
        m.ToDateTime = [ToDateTime stringValue];
        
        GDataXMLElement *Importance = [[arr elementsForName:@"Importance"] objectAtIndex:0];
        m.Importance = [Importance stringValue];
        
        GDataXMLElement *ActivityDescription = [[arr elementsForName:@"ActivityDescription"] objectAtIndex:0];
        m.ActivityDescription = [ActivityDescription stringValue];
        
        GDataXMLElement *IFNotice = [[arr elementsForName:@"IFNotice"] objectAtIndex:0];
        m.IFNotice = [IFNotice stringValue];
        
        GDataXMLElement *TXMobile = [[arr elementsForName:@"TXMobile"] objectAtIndex:0];
        m.TXMobile = [TXMobile stringValue];
        
        GDataXMLElement *SendTime = [[arr elementsForName:@"SendTime"] objectAtIndex:0];
        m.SendTime = [SendTime stringValue];
        
        [listmp addObject:m];
        [m release];
    }
    
    return [listmp autorelease];
}

@end
